﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using BaseballGame.Models;

namespace BaseballGame.Controllers
{
    public class addTeamController : Controller
    {
        private game_entitiesDbContext db = new game_entitiesDbContext();

        //
        // GET: /addTeam/

        public ActionResult Index()
        {
            var teams = db.teams.Include(t => t.Pitcher).Include(t => t.FirstBase).Include(t => t.SecondBase).Include(t => t.ShortStop).Include(t => t.ThirdBase).Include(t => t.Catcher).Include(t => t.LeftField).Include(t => t.Rightfield).Include(t => t.CenterField).Include(t => t.B_FirstBase).Include(t => t.B_SecondBase).Include(t => t.B_ShortStop).Include(t => t.B_ThirdBase).Include(t => t.B_Catcher).Include(t => t.B_LeftField).Include(t => t.B_Midfield).Include(t => t.B_CenterField).Include(t => t.BullPen1).Include(t => t.BullPen2).Include(t => t.BullPen3).Include(t => t.BullPen4).Include(t => t.Closer);
            return View(teams.ToList());
        }

        //
        // GET: /addTeam/Details/5

        public ActionResult Details(int id = 0)
        {
            Team team = db.teams.Find(id);
            if (team == null)
            {
                return HttpNotFound();
            }
            return View(team);
        }

        //
        // GET: /addTeam/Create

        public ActionResult Create()
        {
            ViewBag.PitcherId = new SelectList(db.players, "Id", "player_name");
            ViewBag.FirstBaseId = new SelectList(db.players, "Id", "player_name");
            ViewBag.SecondBaseId = new SelectList(db.players, "Id", "player_name");
            ViewBag.ShortStopId = new SelectList(db.players, "Id", "player_name");
            ViewBag.ThirdBaseId = new SelectList(db.players, "Id", "player_name");
            ViewBag.CatcherId = new SelectList(db.players, "Id", "player_name");
            ViewBag.LeftFieldId = new SelectList(db.players, "Id", "player_name");
            ViewBag.RightfieldId = new SelectList(db.players, "Id", "player_name");
            ViewBag.CenterFieldId = new SelectList(db.players, "Id", "player_name");
            ViewBag.B_FirstBaseId = new SelectList(db.players, "Id", "player_name");
            ViewBag.B_SecondBaseId = new SelectList(db.players, "Id", "player_name");
            ViewBag.B_ShortStopId = new SelectList(db.players, "Id", "player_name");
            ViewBag.B_ThirdBaseId = new SelectList(db.players, "Id", "player_name");
            ViewBag.B_CatcherId = new SelectList(db.players, "Id", "player_name");
            ViewBag.B_LeftFieldId = new SelectList(db.players, "Id", "player_name");
            ViewBag.B_MidfieldId = new SelectList(db.players, "Id", "player_name");
            ViewBag.B_CenterFieldId = new SelectList(db.players, "Id", "player_name");
            ViewBag.BullPen1Id = new SelectList(db.players, "Id", "player_name");
            ViewBag.BullPen2Id = new SelectList(db.players, "Id", "player_name");
            ViewBag.BullPen3Id = new SelectList(db.players, "Id", "player_name");
            ViewBag.BullPen4Id = new SelectList(db.players, "Id", "player_name");
            ViewBag.CloserId = new SelectList(db.players, "Id", "player_name");
            return View();
        }

        //
        // POST: /addTeam/Create

        [HttpPost]
        [ValidateAntiForgeryToken]
        public ActionResult Create(Team team)
        {
            if (ModelState.IsValid)
            {
                db.teams.Add(team);
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            ViewBag.PitcherId = new SelectList(db.players, "Id", "player_name", team.PitcherId);
            ViewBag.FirstBaseId = new SelectList(db.players, "Id", "player_name", team.FirstBaseId);
            ViewBag.SecondBaseId = new SelectList(db.players, "Id", "player_name", team.SecondBaseId);
            ViewBag.ShortStopId = new SelectList(db.players, "Id", "player_name", team.ShortStopId);
            ViewBag.ThirdBaseId = new SelectList(db.players, "Id", "player_name", team.ThirdBaseId);
            ViewBag.CatcherId = new SelectList(db.players, "Id", "player_name", team.CatcherId);
            ViewBag.LeftFieldId = new SelectList(db.players, "Id", "player_name", team.LeftFieldId);
            ViewBag.RightfieldId = new SelectList(db.players, "Id", "player_name", team.RightfieldId);
            ViewBag.CenterFieldId = new SelectList(db.players, "Id", "player_name", team.CenterFieldId);
            ViewBag.B_FirstBaseId = new SelectList(db.players, "Id", "player_name", team.B_FirstBaseId);
            ViewBag.B_SecondBaseId = new SelectList(db.players, "Id", "player_name", team.B_SecondBaseId);
            ViewBag.B_ShortStopId = new SelectList(db.players, "Id", "player_name", team.B_ShortStopId);
            ViewBag.B_ThirdBaseId = new SelectList(db.players, "Id", "player_name", team.B_ThirdBaseId);
            ViewBag.B_CatcherId = new SelectList(db.players, "Id", "player_name", team.B_CatcherId);
            ViewBag.B_LeftFieldId = new SelectList(db.players, "Id", "player_name", team.B_LeftFieldId);
            ViewBag.B_MidfieldId = new SelectList(db.players, "Id", "player_name", team.B_MidfieldId);
            ViewBag.B_CenterFieldId = new SelectList(db.players, "Id", "player_name", team.B_CenterFieldId);
            ViewBag.BullPen1Id = new SelectList(db.players, "Id", "player_name", team.BullPen1Id);
            ViewBag.BullPen2Id = new SelectList(db.players, "Id", "player_name", team.BullPen2Id);
            ViewBag.BullPen3Id = new SelectList(db.players, "Id", "player_name", team.BullPen3Id);
            ViewBag.BullPen4Id = new SelectList(db.players, "Id", "player_name", team.BullPen4Id);
            ViewBag.CloserId = new SelectList(db.players, "Id", "player_name", team.CloserId);
            return View(team);
        }

        //
        // GET: /addTeam/Edit/5

        public ActionResult Edit(int id = 0)
        {
            Team team = db.teams.Find(id);
            if (team == null)
            {
                return HttpNotFound();
            }
            ViewBag.PitcherId = new SelectList(db.players, "Id", "player_name", team.PitcherId);
            ViewBag.FirstBaseId = new SelectList(db.players, "Id", "player_name", team.FirstBaseId);
            ViewBag.SecondBaseId = new SelectList(db.players, "Id", "player_name", team.SecondBaseId);
            ViewBag.ShortStopId = new SelectList(db.players, "Id", "player_name", team.ShortStopId);
            ViewBag.ThirdBaseId = new SelectList(db.players, "Id", "player_name", team.ThirdBaseId);
            ViewBag.CatcherId = new SelectList(db.players, "Id", "player_name", team.CatcherId);
            ViewBag.LeftFieldId = new SelectList(db.players, "Id", "player_name", team.LeftFieldId);
            ViewBag.RightfieldId = new SelectList(db.players, "Id", "player_name", team.RightfieldId);
            ViewBag.CenterFieldId = new SelectList(db.players, "Id", "player_name", team.CenterFieldId);
            ViewBag.B_FirstBaseId = new SelectList(db.players, "Id", "player_name", team.B_FirstBaseId);
            ViewBag.B_SecondBaseId = new SelectList(db.players, "Id", "player_name", team.B_SecondBaseId);
            ViewBag.B_ShortStopId = new SelectList(db.players, "Id", "player_name", team.B_ShortStopId);
            ViewBag.B_ThirdBaseId = new SelectList(db.players, "Id", "player_name", team.B_ThirdBaseId);
            ViewBag.B_CatcherId = new SelectList(db.players, "Id", "player_name", team.B_CatcherId);
            ViewBag.B_LeftFieldId = new SelectList(db.players, "Id", "player_name", team.B_LeftFieldId);
            ViewBag.B_MidfieldId = new SelectList(db.players, "Id", "player_name", team.B_MidfieldId);
            ViewBag.B_CenterFieldId = new SelectList(db.players, "Id", "player_name", team.B_CenterFieldId);
            ViewBag.BullPen1Id = new SelectList(db.players, "Id", "player_name", team.BullPen1Id);
            ViewBag.BullPen2Id = new SelectList(db.players, "Id", "player_name", team.BullPen2Id);
            ViewBag.BullPen3Id = new SelectList(db.players, "Id", "player_name", team.BullPen3Id);
            ViewBag.BullPen4Id = new SelectList(db.players, "Id", "player_name", team.BullPen4Id);
            ViewBag.CloserId = new SelectList(db.players, "Id", "player_name", team.CloserId);
            return View(team);
        }

        //
        // POST: /addTeam/Edit/5

        [HttpPost]
        [ValidateAntiForgeryToken]
        public ActionResult Edit(Team team)
        {
            if (ModelState.IsValid)
            {
                db.Entry(team).State = EntityState.Modified;
                db.SaveChanges();
                return RedirectToAction("Index");
            }
            ViewBag.PitcherId = new SelectList(db.players, "Id", "player_name", team.PitcherId);
            ViewBag.FirstBaseId = new SelectList(db.players, "Id", "player_name", team.FirstBaseId);
            ViewBag.SecondBaseId = new SelectList(db.players, "Id", "player_name", team.SecondBaseId);
            ViewBag.ShortStopId = new SelectList(db.players, "Id", "player_name", team.ShortStopId);
            ViewBag.ThirdBaseId = new SelectList(db.players, "Id", "player_name", team.ThirdBaseId);
            ViewBag.CatcherId = new SelectList(db.players, "Id", "player_name", team.CatcherId);
            ViewBag.LeftFieldId = new SelectList(db.players, "Id", "player_name", team.LeftFieldId);
            ViewBag.RightfieldId = new SelectList(db.players, "Id", "player_name", team.RightfieldId);
            ViewBag.CenterFieldId = new SelectList(db.players, "Id", "player_name", team.CenterFieldId);
            ViewBag.B_FirstBaseId = new SelectList(db.players, "Id", "player_name", team.B_FirstBaseId);
            ViewBag.B_SecondBaseId = new SelectList(db.players, "Id", "player_name", team.B_SecondBaseId);
            ViewBag.B_ShortStopId = new SelectList(db.players, "Id", "player_name", team.B_ShortStopId);
            ViewBag.B_ThirdBaseId = new SelectList(db.players, "Id", "player_name", team.B_ThirdBaseId);
            ViewBag.B_CatcherId = new SelectList(db.players, "Id", "player_name", team.B_CatcherId);
            ViewBag.B_LeftFieldId = new SelectList(db.players, "Id", "player_name", team.B_LeftFieldId);
            ViewBag.B_MidfieldId = new SelectList(db.players, "Id", "player_name", team.B_MidfieldId);
            ViewBag.B_CenterFieldId = new SelectList(db.players, "Id", "player_name", team.B_CenterFieldId);
            ViewBag.BullPen1Id = new SelectList(db.players, "Id", "player_name", team.BullPen1Id);
            ViewBag.BullPen2Id = new SelectList(db.players, "Id", "player_name", team.BullPen2Id);
            ViewBag.BullPen3Id = new SelectList(db.players, "Id", "player_name", team.BullPen3Id);
            ViewBag.BullPen4Id = new SelectList(db.players, "Id", "player_name", team.BullPen4Id);
            ViewBag.CloserId = new SelectList(db.players, "Id", "player_name", team.CloserId);
            return View(team);
        }

        //
        // GET: /addTeam/Delete/5

        public ActionResult Delete(int id = 0)
        {
            Team team = db.teams.Find(id);
            if (team == null)
            {
                return HttpNotFound();
            }
            return View(team);
        }

        //
        // POST: /addTeam/Delete/5

        [HttpPost, ActionName("Delete")]
        [ValidateAntiForgeryToken]
        public ActionResult DeleteConfirmed(int id)
        {
            Team team = db.teams.Find(id);
            db.teams.Remove(team);
            db.SaveChanges();
            return RedirectToAction("Index");
        }

        protected override void Dispose(bool disposing)
        {
            db.Dispose();
            base.Dispose(disposing);
        }
    }
}